package com.gexiao.context.annotation;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * 判断是不是为linux操作系统
 * {@link Condition}
 */
public class LinuxCondition implements Condition {

    /**
     * @param context  servlet上下文信息
     * @param metadata 注解信息
     * @return
     */
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        // ioc容器的工厂信息
        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        // 获取类的加载器
        ClassLoader classLoader = context.getClassLoader();
        // 获取bean的注册信息
        BeanDefinitionRegistry registry = context.getRegistry();
        // 获取运行环境信息
        Environment environment = context.getEnvironment();
        // 获取资源加载器
        ResourceLoader resourceLoader = context.getResourceLoader();
        String os = environment.getProperty("os.name");
        if (os.toLowerCase().contains("linux")) {
            return true;
        }
        return false;
    }
}
